﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows;
using System.Collections;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Diagram;
using System.Windows.Input;
using System.IO;

namespace TouchUmlUI
{
    public class GUIVisible
    {        
        public double viewOpacity { get; set; }
        public StackPanel panel { get; set; }
    }

    public class ItemActor
    {        
        public GUML myGuml { get; set; }
        public Diagram.Aktor aktor { get; set; }
        public ItemActor(Diagram.Aktor a,GUML a_guml) 
        {
            aktor = a;                        
            myGuml = a_guml;
        }
    }

    public class ItemAction
    {
        public GUML myGuml { get; set; }
        public Diagram.Akcja akcja { get; set; }
        public ItemAction(Diagram.Akcja a,GUML a_guml) 
        {
            akcja = a;
            myGuml = a_guml;
        }
    }

    public class ItemAttribute : GUIVisible
    {
        public ItemAttribute item { get; set; }
        public String visibility {get; set;}
        public String name { get; set; }
        public String type { get; set; }
        public Diagram.Atrybut myAttr { get; set; }
        public GUML myGuml { get; set; }

        public ItemAttribute(Diagram.Atrybut attr,GUML a_guml)
        {
            item = this;
            myGuml = a_guml;
            myAttr = attr;
            if (attr.ShowInGui)
                viewOpacity = 1.0f;
            else
                viewOpacity = 0.5f;
            visibility = attr.Visibility.ToString();
            name = attr.Nazwa;
            type = attr.Typ.Nazwa;
        }
    }

    public class ItemMethodArg 
    {
        public String argName { get; set; }
        public String argType { get; set; }

        public ItemMethodArg(String a_argName,String a_argType)
        {
            argName = a_argName;
            argType = a_argType;
        }

    }

    public class ItemMethod : GUIVisible
    {
        public ItemMethod item { get; set; }
        public String visibility { get; set; }
        public String name { get; set; }
        public String type { get; set; }        
        public List<ItemMethodArg> args { get; set; }
        public Diagram.Operacja method { get; set; }
        public GUML myGuml { get; set; }

        ~ItemMethod()
        {
            System.Console.WriteLine("Destroying ItemMethod!");
        }

        public ItemMethod(Operacja meth,GUML aGuml) 
        {
            if (meth.ShowInGui)
                viewOpacity = 1.0f;
            else
                viewOpacity = 0.5f;
            item = this;
            myGuml = aGuml;
            method = meth;
            visibility = meth.Visibility.ToString().ToLower();
            name = meth.Nazwa;
            type = meth.Typ.Nazwa;
            args = new List<ItemMethodArg>();           
            String last_arg = "";            
            for (int i = 0; i < meth.IloscAtrybutow; i++)
            {
                last_arg = meth.GetAtrybut(i).Nazwa;
                if (i < meth.IloscAtrybutow - 1)
                    args.Add(new ItemMethodArg(meth.GetAtrybut(i).Nazwa+",", meth.GetAtrybut(i).Typ.Nazwa));
                else
                    args.Add(new ItemMethodArg(meth.GetAtrybut(i).Nazwa, meth.GetAtrybut(i).Typ.Nazwa));
            }
        }
    }

    public class OurListBox : TreeView
    {
        public ModelDiagramu model;
        public Diagram.Klasa objClass;
        public Diagram.Interfejs objInterface;
        public Point _lastMouseDown;

        // class object fields
        List<ItemAttribute> listA;
        List<ItemMethod> listM;

        public OurListBox() {
            LinearGradientBrush myLinearGradientBrush =
                           new LinearGradientBrush();
            myLinearGradientBrush.StartPoint = new Point(0, 0);
            myLinearGradientBrush.EndPoint = new Point(0, 1);
            myLinearGradientBrush.GradientStops.Add(
                new GradientStop(Color.FromRgb(255,255,255), 0.8));
            myLinearGradientBrush.GradientStops.Add(
                new GradientStop(Color.FromRgb(240,240,240), 1.0));
            this.Background = myLinearGradientBrush;

        }

        private List<ItemAttribute> getClassAttributesList(Diagram.Klasa kuml,GUML aguml) 
        {            
            List<ItemAttribute> list = new List<ItemAttribute>();            
            for (int i = 0; i < kuml.IloscAtrybutow; i++)
            {
                list.Add(new ItemAttribute(kuml.GetAtrybut(i), aguml));
            }
            return list;
        }

        private List<ItemMethod> getClassMethodsList(Diagram.Klasa kuml,GUML aguml)
        {
            List<ItemMethod> list = new List<ItemMethod>();            
            for (int i = 0; i < kuml.IloscOperacji; i++)
            {
                list.Add(new ItemMethod(kuml.GetOperacje(i), aguml));
            }
            return list;
        }

        private List<ItemMethod> getInterfaceMethodsList(Diagram.Interfejs kuml, GUML aguml)
        {
            List<ItemMethod> list = new List<ItemMethod>();
            for (int i = 0; i < kuml.IloscOperacji; i++)
            {
                list.Add(new ItemMethod(kuml.GetOperacje(i), aguml));
            }
            return list;
        }


        public void RefreshWithInterfaceObject(OurCanvas oc)
        {
            Items.Clear();
            this.ItemsSource = null;
            Diagram.Interfejs kuml = objInterface;
            TreeViewItem item = new TreeViewItem();
            TextBox tb = new TextBox();
            tb.Text = kuml.Nazwa;
            item.Header = tb.Text;

            // subitems [ list of attributes and functions ]            
            
            TreeViewItem itemMethodsHeader = new TreeViewItem();
            StackPanel sp = new StackPanel();
            sp.Orientation = Orientation.Horizontal;
            sp.Margin = new Thickness(0);
            sp.Height = 20;
            BitmapImage source = new BitmapImage();
            source.BeginInit();
            source.UriSource = new Uri(Directory.GetCurrentDirectory() + "\\gfx\\methodIcon.png");
            source.EndInit();
            Image img = new Image();
            img.Width = 16;
            img.Height = 16;
            img.Margin = new Thickness(0, 0, 2, 2);
            img.Source = source;
            img.Stretch = System.Windows.Media.Stretch.Fill;
            sp.Children.Add(img);
            source = null;
            TextBlock tbAttr = new TextBlock();
            tbAttr.Text = "Metody";
            sp.Children.Add(tbAttr);
            itemMethodsHeader.Header = sp;

            //assignin icons                     
            //filling attributes and method items\            
            if (listM != null)
            {
                listM.Clear();
                listM = null;
            } 
            UMLObj umlObj = findUMLByName(kuml.Nazwa, oc);            
            listM = getInterfaceMethodsList(kuml, umlObj.guml);            
            itemMethodsHeader.ItemsSource = listM;
            item.Items.Add(itemMethodsHeader);            
            itemMethodsHeader.IsExpanded = true;
            item.IsExpanded = true;

            List<AssociationObj> ret = SignalR.windowParent.findAllAssociationsForObject(umlObj);
            TreeViewItem itemAssociations = new TreeViewItem();
            itemAssociations.Header = "Asocjacje";
            itemAssociations.IsExpanded = true;
            
            foreach (AssociationObj aO in ret)
            {
                Diagram.Asocjacja aObj = aO.guml.obj_uml as Diagram.Asocjacja;
                TreeViewItem i = new TreeViewItem();
                i.Header = "Asocjacja"; // TYPY !!
                i.Items.Add("Z: " + getElementName(aObj[0].OwnedEnd));
                i.Items.Add("Do: " + getElementName(aObj[1].OwnedEnd));
                i.Tag = aO.guml.obj_uml;
                i.IsExpanded = true;
                itemAssociations.Items.Add(i);
            }

            item.Items.Add(itemAssociations);

            Items.Add(item); 
        }

        public void RefreshWithClassObject(OurCanvas oc)
        {

            Items.Clear();
            this.ItemsSource = null;
            Diagram.Klasa kuml = objClass;
            TreeViewItem item = new TreeViewItem();
            TextBox tb = new TextBox();
            tb.Text = kuml.Nazwa;
            item.Header = tb.Text;

            // subitems [ list of attributes and functions ]
            TreeViewItem itemAttrHeader = new TreeViewItem();
            StackPanel sp = new StackPanel();
            sp.Orientation = Orientation.Horizontal;
            sp.Margin = new Thickness(0);
            sp.Height = 20;
            BitmapImage source = new BitmapImage();
            source.BeginInit();
            source.UriSource = new Uri(Directory.GetCurrentDirectory() + "\\gfx\\attributeIcon.png");
            source.EndInit();
            Image img = new Image();
            img.Width = 16;
            img.Height = 16;
            img.Margin = new Thickness(0, 0, 2, 0);
            img.Source = source;
            img.Stretch = System.Windows.Media.Stretch.Fill;            
            sp.Children.Add(img);
            source = null;
            TextBlock tbAttr = new TextBlock();
            tbAttr.Text = "Atrybuty";
            sp.Children.Add(tbAttr);
            itemAttrHeader.Header = sp;

            TreeViewItem itemMethodsHeader = new TreeViewItem();
            sp = new StackPanel();
            sp.Orientation = Orientation.Horizontal;
            sp.Margin = new Thickness(0);
            sp.Height = 20;
            source = new BitmapImage();
            source.BeginInit();
            source.UriSource = new Uri(Directory.GetCurrentDirectory() + "\\gfx\\methodIcon.png");
            source.EndInit();
            img = new Image();
            img.Width = 16;
            img.Height = 16;
            img.Margin = new Thickness(0, 0, 2, 2);
            img.Source = source;
            img.Stretch = System.Windows.Media.Stretch.Fill;
            sp.Children.Add(img);
            source = null;
            tbAttr = new TextBlock();
            tbAttr.Text = "Metody";
            sp.Children.Add(tbAttr);
            itemMethodsHeader.Header = sp;

            //assignin icons                     
            //filling attributes and method items\            
            if (listM!=null)
            {                
                listM.Clear();
                listM = null;
            }
            if (listA!=null)
            {
                listA.Clear();
                listA = null;                
            }
            UMLObj umlObj = findUMLByName(kuml.Nazwa, oc);
            listA = getClassAttributesList(kuml,umlObj.guml);
            listM = getClassMethodsList(kuml,umlObj.guml);
            itemAttrHeader.ItemsSource = listA;            
            itemMethodsHeader.ItemsSource = listM;
            if (!(umlObj.getType() == typeof(InterfejsObj)))
                item.Items.Add(itemAttrHeader);
            item.Items.Add(itemMethodsHeader);                
            itemAttrHeader.IsExpanded = true;
            itemMethodsHeader.IsExpanded = true;
            item.IsExpanded = true;

            List<AssociationObj> ret = SignalR.windowParent.findAllAssociationsForObject(umlObj);
            TreeViewItem itemAssociations = new TreeViewItem();           
            itemAssociations.Header = "Asocjacje";
            itemAssociations.IsExpanded = true;


            foreach (AssociationObj aO in ret)
            {
                Diagram.Asocjacja aObj = aO.guml.obj_uml as Diagram.Asocjacja;
                TreeViewItem i = new TreeViewItem();
                i.Header = "Asocjacja"; // TYPY !!
                i.Items.Add("Z: " + getElementName(aObj[0].OwnedEnd));
                i.Items.Add("Do: " + getElementName(aObj[1].OwnedEnd));
                i.Tag = aO.guml.obj_uml;
                i.IsExpanded = true;
                itemAssociations.Items.Add(i);
            }

            item.Items.Add(itemAssociations);

            Items.Add(item); 

        }

        private UMLObj findUMLByName(String findName,OurTabbedConrol otc)
        {            
            UMLObj ret = null;
            foreach (OurTab tab in otc.Tabs)
            {
                if (tab.canvas is OurCanvas)
                {
                    ret = (tab.canvas as OurCanvas).findUMLObjByName(findName);
                    if (ret != null) break;
                }
            }
            return ret;
        }


        private UMLObj findUMLByName(String findName, OurCanvas oc)
        {
            UMLObj ret = null;                       
            ret = oc.findUMLObjByName(findName);
            return ret;
        }

        private String getElementName(Diagram.Element element) 
        {
            if (element.Nazwa!=null)
                return element.Nazwa;
            return "Nazwa.Equals(null)!";
        }

        public void Refresh(OurTabbedConrol otc) 
        {

            Items.Clear();
            foreach (OurTab tab in otc.Tabs)
            {
                TreeViewItem root = new TreeViewItem();
                root.Header = tab.getTitle();

                foreach (UMLObj umlObj in ((OurCanvas)tab.canvas).al)
                {
                    Type objectType = umlObj.getType();
                    TreeViewItem item = new TreeViewItem();
                    if (objectType==typeof(AktorObj))
                    {
                    }
                    else if (objectType == typeof(AkcjaObj))
                    {
                    }
                    else if (objectType==typeof(KlasaObj))
                    {                        
                        TextBox tb = new TextBox();
                        tb.Text = umlObj.guml.obj_uml.Nazwa;
                        item.Header = tb.Text;
                        // subitems [ list of attributes and functions ]
                        TreeViewItem itemAttrHeader = new TreeViewItem();
                        StackPanel sp = new StackPanel();
                        sp.Orientation = Orientation.Horizontal;
                        sp.Margin = new Thickness(0);
                        sp.Height = 20;
                        BitmapImage source = new BitmapImage();
                        source.BeginInit();
                        source.UriSource = new Uri(Directory.GetCurrentDirectory() + "\\gfx\\attributeIcon.png");
                        source.EndInit();
                        Image img = new Image();
                        img.Width = 16;
                        img.Height = 16;
                        img.Margin = new Thickness(0, 0, 2, 0);
                        img.Source = source;
                        img.Stretch = System.Windows.Media.Stretch.Fill;
                        sp.Children.Add(img);
                        TextBlock tbAttr = new TextBlock();
                        tbAttr.Text = LocalizationManager.MODEL_ATTRIBUTES_TITLE;
                        sp.Children.Add(tbAttr);
                        itemAttrHeader.Header = sp;

                        TreeViewItem itemMethodsHeader = new TreeViewItem();
                        sp = new StackPanel();
                        sp.Orientation = Orientation.Horizontal;
                        sp.Margin = new Thickness(0);
                        sp.Height = 20;
                        source = new BitmapImage();
                        source.BeginInit();
                        
                        source.UriSource = new Uri(Directory.GetCurrentDirectory() + "\\gfx\\methodIcon.png");
                        source.EndInit();
                        img = new Image();
                        img.Width = 16;
                        img.Height = 16;
                        img.Margin = new Thickness(0, 0, 2, 2);
                        img.Source = source;
                        img.Stretch = System.Windows.Media.Stretch.Fill;
                        sp.Children.Add(img);
                        tbAttr = new TextBlock();
                        tbAttr.Text = LocalizationManager.MODEL_METHODS_TITLE;
                        sp.Children.Add(tbAttr);
                        itemMethodsHeader.Header = sp;
                        
                        itemAttrHeader.ItemsSource = getClassAttributesList(umlObj.guml.obj_uml as Diagram.Klasa, umlObj.guml);
                        itemMethodsHeader.ItemsSource = getClassMethodsList(umlObj.guml.obj_uml as Diagram.Klasa, umlObj.guml);
                        item.Items.Add(itemAttrHeader);
                        item.Items.Add(itemMethodsHeader);
                        List<AssociationObj> ret = SignalR.windowParent.findAllAssociationsForObject(umlObj);
                        TreeViewItem itemAssociations = new TreeViewItem();
                        itemAssociations.Header = LocalizationManager.MODEL_ASSOCIATIONS_TITLE;
                        itemAssociations.IsExpanded = true;


                        foreach (AssociationObj aO in ret)
                        {
                            Diagram.Asocjacja aObj = aO.guml.obj_uml as Diagram.Asocjacja;
                            TreeViewItem i = new TreeViewItem();
                            i.Header = "Asocjacja"; // TYPY !!
                            i.Items.Add("Z: " + getElementName(aObj[0].OwnedEnd));
                            i.Items.Add("Do: " + getElementName(aObj[1].OwnedEnd));
                            i.Tag = aO.guml.obj_uml;
                            itemAssociations.Items.Add(i);
                        }

                        item.Items.Add(itemAssociations);
                        root.Items.Add(item);
                    }                    
                    else if (objectType==typeof(InterfejsObj))
                    {
                    }
                    else if (objectType==typeof(NotatkaObj))
                    {
                    }
                }

                Items.Add(root);
            }


            //Items.Clear();
            //if (model == null) return;
            //Console.WriteLine("Refresh(" + otc + "), size: "+model.Elementy.Count);

            //TreeViewItem dKlas = new TreeViewItem();
            //TreeViewItem dPrzypadkowUzycia = new TreeViewItem();
            //dKlas.Header = "Diagram klas";
            //dPrzypadkowUzycia.Header = "Diagram przypadków użycia";
            

            //foreach (OurTab tab in otc.Tabs)
            //{                
            //    foreach (Object obj in ((OurCanvas)tab.canvas).model.Elementy)
            //    {                    
            //        Console.WriteLine("obj is: " + obj.ToString());
            //        TreeViewItem item = new TreeViewItem();
            //        if (obj is Diagram.Akcja) 
            //        {
            //            Diagram.Akcja aObj = obj as Diagram.Akcja;
            //            UMLObj umlObj = findUMLByName(aObj.Nazwa, otc);
            //            dPrzypadkowUzycia.Items.Add(new ItemAction(aObj, umlObj.guml));

            //        /*    TreeViewItem last = dPrzypadkowUzycia.Items[dPrzypadkowUzycia.Items.Count - 1] as TreeViewItem;
            //            List<AssociationObj> ret = SignalR.windowParent.findAllAssociationsForObject(umlObj);
            //            TreeViewItem itemAssociations = new TreeViewItem();
            //            itemAssociations.Header = "Asocjacje";
            //            itemAssociations.IsExpanded = true;

            //            foreach (AssociationObj aO in ret)
            //            {
            //                Diagram.Asocjacja aTempObj = aO.guml.obj_uml as Diagram.Asocjacja;
            //                TreeViewItem i = new TreeViewItem();
            //                i.Header = "Asocjacja"; // TYPY !!
            //                i.Items.Add("Z: " + getElementName(aTempObj[0].OwnedEnd));
            //                i.Items.Add("Do: " + getElementName(aTempObj[1].OwnedEnd));
            //                i.Tag = aO.guml.obj_uml;
            //                itemAssociations.Items.Add(i);
            //            }
            //            last.Items.Add(itemAssociations);*/


            //            item = null;
            //        }
            //        else if (obj is Diagram.Aktor)
            //        {
            //            Diagram.Aktor aObj = obj as Diagram.Aktor;
            //            UMLObj umlObj = findUMLByName(aObj.Nazwa, otc);
            //            dPrzypadkowUzycia.Items.Add(new ItemActor(aObj, umlObj.guml));
            //        /*    dPrzypadkowUzycia.UpdateLayout();
            //            TreeViewItem last = dPrzypadkowUzycia.Items[dPrzypadkowUzycia.Items.Count - 1] as TreeViewItem;
            //            List<AssociationObj> ret = SignalR.windowParent.findAllAssociationsForObject(umlObj);
            //            TreeViewItem itemAssociations = new TreeViewItem();
            //            itemAssociations.Header = "Asocjacje";
            //            itemAssociations.IsExpanded = true;

            //            foreach (AssociationObj aO in ret)
            //            {
            //                Diagram.Asocjacja aTempObj = aO.guml.obj_uml as Diagram.Asocjacja;
            //                TreeViewItem i = new TreeViewItem();
            //                i.Header = "Asocjacja"; // TYPY !!
            //                i.Items.Add("Z: " + getElementName(aTempObj[0].OwnedEnd));
            //                i.Items.Add("Do: " + getElementName(aTempObj[1].OwnedEnd));
            //                i.Tag = aO.guml.obj_uml;
            //                itemAssociations.Items.Add(i);
            //            }
            //            last.Items.Add(itemAssociations);*/


            //            item = null;
            //        }
            //       /* else if (obj is Diagram.Asocjacja)
            //        {
            //            Diagram.Asocjacja aObj = obj as Diagram.Asocjacja;                        
            //            item.Header = "Asocjacja";
            //            item.Items.Add("Z: " + getElementName(aObj[0].OwnedEnd));
            //            item.Items.Add("Do: " + getElementName(aObj[1].OwnedEnd));
            //            item.Tag = obj;
            //            Items.Add(item);
            //        }*/
            //     /*   else if (obj is Diagram.Notatka)
            //        {
            //            Diagram.Notatka nObj = obj as Diagram.Notatka;                        
            //            item.Header = getElementName(nObj);
            //            item.Items.Add(nObj.Tekst);
            //            item.Tag = obj;
            //            Items.Add(item);
            //        }*/
            //        else if (obj is Diagram.Interfejs)
            //        {
            //            Diagram.Interfejs kuml = (Diagram.Interfejs)obj;
            //            item.Tag = obj;
            //            UMLObj umlObj = findUMLByName(kuml.Nazwa, otc);
                        
            //            TextBox tb = new TextBox();
            //            tb.Text = kuml.Nazwa;
            //            item.Header = tb.Text;

            //            TreeViewItem itemMethodsHeader = new TreeViewItem();
            //            StackPanel sp = new StackPanel();
            //            sp.Orientation = Orientation.Horizontal;
            //            sp.Margin = new Thickness(0);
            //            sp.Height = 20;
            //            BitmapImage source = new BitmapImage();
            //            source.BeginInit();
            //            source.UriSource = new Uri(new Uri(Directory.GetCurrentDirectory()), "gfx\\methodIcon.png");
            //            source.EndInit();
            //            Image img = new Image();
            //            img.Width = 16;
            //            img.Height = 16;
            //            img.Margin = new Thickness(0, 0, 2, 2);
            //            img.Source = source;
            //            img.Stretch = System.Windows.Media.Stretch.Fill;
            //            sp.Children.Add(img);
            //            TextBlock tbAttr = new TextBlock();
            //            tbAttr.Text = "Metody";
            //            itemMethodsHeader.Header = sp;
            //            sp.Children.Add(tbAttr);
            //            itemMethodsHeader.ItemsSource = getInterfaceMethodsList(kuml, umlObj.guml);
            //            item.Items.Add(itemMethodsHeader);
            //            dKlas.Items.Add(item);

            //            List<AssociationObj> ret = SignalR.windowParent.findAllAssociationsForObject(umlObj);
            //            TreeViewItem itemAssociations = new TreeViewItem();
            //            itemAssociations.Header = "Asocjacje";
            //            itemAssociations.IsExpanded = true;

            //            foreach (AssociationObj aO in ret)
            //            {
            //                Diagram.Asocjacja aObj = aO.guml.obj_uml as Diagram.Asocjacja;
            //                TreeViewItem i = new TreeViewItem();
            //                i.Header = "Asocjacja"; // TYPY !!
            //                i.Items.Add("Z: " + getElementName(aObj[0].OwnedEnd));
            //                i.Items.Add("Do: " + getElementName(aObj[1].OwnedEnd));
            //                i.Tag = aO.guml.obj_uml;
            //                itemAssociations.Items.Add(i);
            //            }

            //            item.Items.Add(itemAssociations);

            //        }
            //        else if (obj is Diagram.Klasa)
            //        {
            //            item.Tag = obj;
            //            Diagram.Klasa kuml = (Diagram.Klasa)obj;

            //            UMLObj umlObj = findUMLByName(kuml.Nazwa, otc);
                        
            //            TextBox tb = new TextBox();
            //            tb.Text = kuml.Nazwa;
            //            item.Header = tb.Text;

            //            // subitems [ list of attributes and functions ]
            //            TreeViewItem itemAttrHeader = new TreeViewItem();
            //            StackPanel sp = new StackPanel();
            //            sp.Orientation = Orientation.Horizontal;
            //            sp.Margin = new Thickness(0);
            //            sp.Height = 20;
            //            BitmapImage source = new BitmapImage();
            //            source.BeginInit();
            //            source.UriSource = new Uri(new Uri(Directory.GetCurrentDirectory()), "gfx\\attributeIcon.png");
            //            source.EndInit();
            //            Image img = new Image();
            //            img.Width = 16;
            //            img.Height = 16;
            //            img.Margin = new Thickness(0, 0, 2, 0);
            //            img.Source = source;
            //            img.Stretch = System.Windows.Media.Stretch.Fill;
            //            sp.Children.Add(img);
            //            TextBlock tbAttr = new TextBlock();
            //            tbAttr.Text = "Atrybuty";
            //            sp.Children.Add(tbAttr);
            //            itemAttrHeader.Header = sp;

            //            TreeViewItem itemMethodsHeader = new TreeViewItem();
            //            sp = new StackPanel();
            //            sp.Orientation = Orientation.Horizontal;
            //            sp.Margin = new Thickness(0);
            //            sp.Height = 20;
            //            source = new BitmapImage();
            //            source.BeginInit();
            //            source.UriSource = new Uri(new Uri(Directory.GetCurrentDirectory()), "gfx\\methodIcon.png");
            //            source.EndInit();
            //            img = new Image();
            //            img.Width = 16;
            //            img.Height = 16;
            //            img.Margin = new Thickness(0, 0, 2, 2);
            //            img.Source = source;
            //            img.Stretch = System.Windows.Media.Stretch.Fill;
            //            sp.Children.Add(img);
            //            tbAttr = new TextBlock();
            //            tbAttr.Text = "Metody";
            //            sp.Children.Add(tbAttr);
            //            itemMethodsHeader.Header = sp;
            //            //assignin icons                     
            //            //filling attributes and method items
            //            itemAttrHeader.ItemsSource = getClassAttributesList(kuml, umlObj.guml);
            //            itemMethodsHeader.ItemsSource = getClassMethodsList(kuml, umlObj.guml);
            //            item.Items.Add(itemAttrHeader);                            
            //            item.Items.Add(itemMethodsHeader);
            //            List<AssociationObj> ret = SignalR.windowParent.findAllAssociationsForObject(umlObj);
            //            TreeViewItem itemAssociations = new TreeViewItem();
            //            itemAssociations.Header = "Asocjacje";
            //            itemAssociations.IsExpanded = true;


            //            foreach (AssociationObj aO in ret)
            //            {
            //                Diagram.Asocjacja aObj = aO.guml.obj_uml as Diagram.Asocjacja;
            //                TreeViewItem i = new TreeViewItem();
            //                i.Header = "Asocjacja"; // TYPY !!
            //                i.Items.Add("Z: " + getElementName(aObj[0].OwnedEnd));
            //                i.Items.Add("Do: " + getElementName(aObj[1].OwnedEnd));
            //                i.Tag = aO.guml.obj_uml;
            //                itemAssociations.Items.Add(i);
            //            }

            //            item.Items.Add(itemAssociations);

            //            dKlas.Items.Add(item);
            //        }
            //    }
            //}
            //Items.Add(dKlas);            
            //Items.Add(dPrzypadkowUzycia);            
       
            //dKlas.IsExpanded = true;
            //dPrzypadkowUzycia.IsExpanded = true;            
        }
        
    }
}
